package com.example.framework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

public abstract class WebDriverHelper extends BaseHelper {

    protected WebDriver driver;

    public WebDriverHelper(HelperManager manager){
        super(manager);
        this.driver = manager.getDriver();
    }

    public void click(By locator) {
        driver.findElement(locator).click();
    }

    public void inputTextToEditBox(By editBoxLocator, String textForInput) {
        if (textForInput != null){
            driver.findElement(editBoxLocator).clear();
            driver.findElement(editBoxLocator).sendKeys(textForInput);
        }
    }

    public void selectDropdownListItemByText(By DropdownListLocator, String itemText) {
        if (itemText != null){
            new Select(driver.findElement(DropdownListLocator)).selectByVisibleText(itemText);
        }
    }

    public void openUrl(String url){
        driver.get(manager.getProperty("baseUrl") + url);
    }

    public void openAbsoluteUrl(String url) {
        driver.get(manager.getProperty(url));
    }
}
